<!-- 查看团队成员信息 -->
<template>
  <a-modal
    :visible="viewCenterModalVisible"
    :title="$t('all.autotext1459')"
    :footer="null"
    width="80%"
    @cancel="handleCancel(0)"
  >
    <a-descriptions :title="$t('all.autotext720')" bordered>
      <a-descriptions-item :label="$t('all.autotext839')">{{ viewCenterMemberDetail.researchNo }}</a-descriptions-item>
      <a-descriptions-item :label="$t('all.autotext898')">{{ viewCenterMemberDetail.roleName }}</a-descriptions-item>
      <a-descriptions-item :label="$t('all.autotext1175')">{{ hospitalNameProp }}</a-descriptions-item>
      <a-descriptions-item :label="$t('all.autotext977')">{{ viewCenterMemberDetail.name }}</a-descriptions-item>
      <a-descriptions-item :label="$t('all.autotext682')">{{ viewCenterMemberDetail.phone }}</a-descriptions-item>
      <a-descriptions-item :label="$t('all.autotext44')">{{ viewCenterMemberDetail.email }}</a-descriptions-item>
      <a-descriptions-item :label="$t('all.autotext192')">{{ viewCenterMemberDetail.evidenceType | enumValueByKey($const.DOCUMENT_TYPE) }}</a-descriptions-item>
      <a-descriptions-item :label="$t('all.autotext1359')">{{ viewCenterMemberDetail.idCard }}</a-descriptions-item>
      <a-descriptions-item label="是否审核人">{{ viewCenterMemberDetail.isCheck == 1 ? $t('all.autotext279') : $t('all.autotext957') }}</a-descriptions-item>
      <a-descriptions-item :label="$t('all.autotext329')">{{ viewCenterMemberDetail.mainResearch == 1 ? $t('all.autotext279') : $t('all.autotext957') }}</a-descriptions-item>
      <a-descriptions-item :label="$t('all.autotext667')">{{ viewCenterMemberDetail.authStatus | enumValueByKey($const.CENTER_MEMBER_STATUS) }}</a-descriptions-item>
    </a-descriptions>
    <div v-if="$auth('PROJECT.PROJECT_RESEARCH_MEMBER_EDIT') || auditPmsVisible">
      <div>
        <a-descriptions :title="$t('all.autotext560')" :style="{ marginTop: '32px' }" />
        <a-radio-group v-model="viewCenterMemberDetail.mainResearch">
          <a-popconfirm
            :title="titleShow"
            :ok-text="$t('all.autotext792')"
            :cancel-text="$t('all.autotext975')"
            @confirm="clickConfirm(1)"
          >
            <a-radio :value="1">{{ $t('all.autotext279') }}</a-radio>
          </a-popconfirm>
          <a-popconfirm
            :title="disTitleShow"
            :ok-text="$t('all.autotext792')"
            :cancel-text="$t('all.autotext975')"
            @confirm="clickConfirm(0)"
          >
            <a-radio :value="0">{{ $t('all.autotext957') }}</a-radio>
          </a-popconfirm>
        </a-radio-group>
      </div>
      <div>
        <a-descriptions :title="$t('all.autotext961')" :style="{ marginTop: '32px' }" />
        <a-radio-group v-model="viewCenterMemberDetail.isCheck">
          <a-popconfirm
            :title="$t('all.autotext319')"
            :ok-text="$t('all.autotext792')"
            :cancel-text="$t('all.autotext975')"
            @confirm="setApprover(1)"
          >
            <a-radio :value="1">{{ $t('all.autotext279') }}</a-radio>
          </a-popconfirm>
          <a-popconfirm
            :title="$t('all.autotext729')"
            :ok-text="$t('all.autotext792')"
            :cancel-text="$t('all.autotext975')"
            @confirm="setApprover(0)"
          >
            <a-radio :value="0">{{ $t('all.autotext957') }}</a-radio>
          </a-popconfirm>
        </a-radio-group>
      </div>
      <div v-if="viewCenterMemberDetail.authStatus == 3">
        <a-descriptions :title="$t('all.autotext883')" :style="{ marginTop: '32px' }" />
        <a-textarea
          :auto-size="{ minRows: 5 }"
          :placeholder="$t('all.autotext1241')"
          allow-clear
          v-model="commitData.refuseReason"
        />
        <div style="margin-top: 20px">
          <a-button type="primary" @click="clickSubject(1)" style="margin-right: 20px">{{ $t('all.autotext694') }}</a-button>
          <a-button @click="clickSubject(2)">{{ $t('all.autotext1072') }}</a-button>
        </div>
      </div>
    </div>
  </a-modal>
</template>

<script>
import { getCenterDetail, updateCenterMember, updateMainRes, updateApprover } from '@/api/overview/member'
import { getInfo } from '@/api/login'

export default {
  props: {
    viewCenterModalVisible: {
      type: Boolean,
      default: false
    },
    viewCenterMemberDetail: {
      type: Object,
      default: () => {
        return {}
      }
    },
    // 将选择的医院传递过来用于展示
    hospitalNameProp: {
      type: String,
      default: ''
    },
    mProId: {
      type: [Number, String],
      default: null
    }
  },
  data () {
    return {
      commitData: {},
      titleShow: null,
      disTitleShow: null,
      statusValue: null,
      auditPmsVisible: false
    }
  },
  created () {
  },
  watch: {
    viewCenterModalVisible (e) {
      if (e) {
        if (this.mProId) {
          getInfo({ proId: this.mProId }).then(res => {
            this.auditPmsVisible = !!(res.pms && res.pms.indexOf('PROJECT_RESEARCH_MEMBER_EDIT') >= 0)
          })
        }
      }
    }
  },
  methods: {
    // 请求详情筛选负责人name
    getCenterDetail (val, label) {
      getCenterDetail({ resId: val })
        .then(res => {
          const target = res.detailsList.content.find(item => item.mainResearch === 1)
          if (target) {
            this.titleShow = this.$t('all.autotext877.1') + target.name + this.$t('all.autotext877.2')
          } else {
            this.titleShow = this.$t('all.autotext1199.1') + this.viewCenterMemberDetail.name + this.$t('all.autotext1199.2')
          }
          this.disTitleShow = this.$t('all.autotext895.1') + this.viewCenterMemberDetail.name + this.$t('all.autotext895.2')
          if (label) {
            updateMainRes({ id: this.viewCenterMemberDetail.id, mainResearch: this.statusValue, researchId: this.viewCenterMemberDetail.researchId, proId: this.viewCenterMemberDetail.proId })
              .then(res => {
                this.viewCenterMemberDetail.mainResearch = this.statusValue
                this.$message.success(this.$t('all.autotext227'))
                this.handleCancel(1)
              })
              .catch(() => {})
          }
        })
        .catch(() => {})
    },
    clickConfirm (val) {
      this.statusValue = val
      this.getCenterDetail(this.viewCenterMemberDetail.researchId, 1)
    },
    // 设为审核人
    setApprover (val) {
      updateApprover({ id: this.viewCenterMemberDetail.id, proId: this.viewCenterMemberDetail.proId, isCheck: val })
        .then(res => {
          this.$message.success(this.$t('all.autotext205'))
          this.handleCancel(1)
        })
    },
    // 点击同意/拒绝
    clickSubject (val) {
      this.approvalMember()
      if (val === 2) {
        if (this.commitData.refuseReason === null || this.commitData.refuseReason === undefined || this.commitData.refuseReason === '') {
          this.$message.error(this.$t('all.autotext653'))
          return false
        }
      }
      this.commitData.id = this.viewCenterMemberDetail.id
      this.commitData.authStatus = val
      updateCenterMember({ ...this.commitData })
        .then(res => {
          this.$message.success(this.$t('all.autotext99'))
          this.handleCancel(1)
        })
        .catch(() => {})
    },
    // 点击取消对话框消失
    handleCancel (val) {
      this.commitData = {}
      this.$emit('closeViewCenterModal', val)
    },
    // 成员审核埋点
    approvalMember () {}
  }
}
</script>

<style scoped lang="scss">

</style>
